[id].vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. <template>
  2. <div id="newsList">
  3. <!-- 页面头部 -->
  4. <HomePageHead></HomePageHead>
  5. <!-- 导航栏 -->
  6. <HomePageNavigation></HomePageNavigation>
  7. <!-- 列表页广告一 -->
  8. <HomeTopTen :imgurl="adImg1" v-if="adImg1"></HomeTopTen>
  9. <!-- 搜索框 -->
  10. <div class="search">
  11. <div class="inner">
  12. <input v-model="keywordInput" type="text" placeholder="请输入搜索内容">
  13. <button @click="goSearch">搜索</button>
  14. </div>
  15. </div>
  16. <div class="breadcrumb phone_none">
  17. <div class="inner">
  18. <span class="location">当前位置:</span>
  19. <el-breadcrumb :separator-icon="ArrowRight">
  20. <el-breadcrumb-item>
  21. <NuxtLink to="/">首页</NuxtLink>
  22. </el-breadcrumb-item>
  23. <el-breadcrumb-item>搜索</el-breadcrumb-item>
  24. </el-breadcrumb>
  25. </div>
  26. </div>
  27. <div class="breadcrumb_box pc_none">
  28. <span class=" ">当前位置:</span>
  29. <NuxtLink to="/">首页</NuxtLink>
  30. <span class=" ">&gt;</span>
  31. <span class=" ">搜索</span>
  32. </div>
  33. <div class="newsList">
  34. <div class="inner">
  35. <div class="innerLeft">
  36. <ul class="list" v-if="newsList.length >= 0">
  37. <li v-for="(item, index) in newsList" :key="index">
  38. <NuxtLink :href="getLinkPathDetail(item)" :title="item.title" :target="item.islink == 1 ? '_blank' : '_self'">
  39. {{ item.title }}
  40. </NuxtLink>
  41. <span class="time right phone_none">{{getTime(item.updated_at,'month',1)}}</span>
  42. </li>
  43. </ul>
  44. <div v-if="newsList.length == 0" class="empty">
  45. <div>
  46. <img src="../../public/search/empty.png" alt="暂无内容">
  47. <p>暂无搜索数据</p>
  48. </div>
  49. </div>
  50. <!-- 分页器 -->
  51. <div class="pagination pagination_phone_none" v-if="total > 0">
  52. <el-pagination
  53. size="small"
  54. background
  55. layout="prev, pager, next"
  56. :total="total"
  57. class="mt-4"
  58. :page-size="pageSize"
  59. prev-text="上一页"
  60. next-text="下一页"
  61. @change="changePage"
  62. />
  63. </div>
  64. <div class="pagination pagination_pc_none" v-if="total > 0">
  65. <el-pagination
  66. pager-count="5"
  67. class="mt-4"
  68. size="small"
  69. background
  70. layout=" pager "
  71. :total="total"
  72. page-size="pageSize"
  73. @change="changePage"
  74. />
  75. </div>
  76. </div>
  77. </div>
  78. </div>
  79. <!-- 列表页广告二 -->
  80. <HomeTopTen :imgurl="adImg2" v-if="adImg2"></HomeTopTen>
  81. <!-- 页面底部 -->
  82. <HomeFoot1></HomeFoot1>
  83. </div>
  84. </template>
  85. <script setup>
  86. //1.页面依赖 start ---------------------------------------->
  87. import { ElBreadcrumb, ElBreadcrumbItem, ElPagination } from 'element-plus'
  88. import { ArrowRight } from '@element-plus/icons-vue'
  89. import { ref, onMounted } from 'vue';
  90. //1.页面依赖 end ---------------------------------------->
  91. //2.获取url中的参数 start ---------------------------------------->
  92. const route = useRoute();
  93. const pageCatids = ""
  94. let keywordInput = ref("");
  95. if(route.params.id=='search'){
  96. //该处用于带有文字出入的搜索栏跳转
  97. console.log("检测到从搜索栏跳转的搜索!")
  98. console.log(route.query.type)//左侧搜索下拉框的值
  99. console.log(route.query.keyword)//右侧输入框的值
  100. //目前route.query.type 1=资讯 2=商城 3=招工招聘
  101. //但是商城和招工招聘暂没有开发完,所以这里不需要考虑 只给keyword赋值即可
  102. keywordInput.value = route.query.keyword;
  103. }else{
  104. //该处用于搜索栏中含有地区的跳转
  105. const pageCatids = route.params.id
  106. }
  107. const pageDepartment_id = route.query.department_id;
  108. //2.获取url中的参数 end ---------------------------------------->
  109. //3.在该页进行搜索 start ---------------------------------------->
  110. //3.1 分页
  111. let total = useState("total", () => 0)
  112. let page = useState("page", () => 1)
  113. let pageSize = useState("pageSize", () => 20)
  114. //3.2 获得新闻列表
  115. const newsList = ref([]);
  116. //3.3 在本页进行搜索的方法
  117. let goSearch = async () => {
  118. console.log(page.value)
  119. console.log(pageSize.value)
  120. console.log(keywordInput.value)
  121. console.log(pageCatids)
  122. console.log(pageDepartment_id)
  123. const listData = await requestDataPromise('/web/selectWebsiteCategory', {
  124. method: 'GET',
  125. query: {
  126. 'page': page.value,
  127. 'pageSize': pageSize.value,
  128. 'keyword':keywordInput.value,
  129. 'cityid':pageCatids,
  130. 'department_id':pageDepartment_id
  131. },
  132. });
  133. if(listData.data.rows){
  134. console.log(listData)
  135. newsList.value = listData.data.rows;
  136. total.value = listData.data.count;
  137. }else{
  138. newsList.value = [];
  139. total.value = 0;
  140. }
  141. }
  142. goSearch();
  143. //3.4 分页事件
  144. let changePage = (value) => {
  145. console.log("当前页码", value);
  146. page.value = value
  147. console.log(page.value);
  148. goSearch()
  149. }
  150. //3.在该页进行搜索 end ---------------------------------------->
  151. //4.广告 start ---------------------------------------->
  152. let adImg1 = ref([]);
  153. let adImg2 = ref([]);
  154. onMounted(async () => {
  155. //从客户端获取行政职能部门 加快打开速度
  156. const { $webUrl, $CwebUrl } = useNuxtApp();
  157. //广告1
  158. let url = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=nfcpgxw_search_0001`
  159. const responseAd1 = await fetch(url, {
  160. headers: {
  161. 'Content-Type': 'application/json',
  162. 'Userurl': $CwebUrl,
  163. 'Origin': $CwebUrl
  164. }
  165. });
  166. const resultAd1 = await responseAd1.json();
  167. adImg1.value = resultAd1.data[0];
  168. //广告2
  169. let url2 = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=nfcpgxw_search_0002`
  170. const responseAd2 = await fetch(url2, {
  171. headers: {
  172. 'Content-Type': 'application/json',
  173. 'Userurl': $CwebUrl,
  174. 'Origin': $CwebUrl
  175. }
  176. });
  177. const resultAd2 = await responseAd2.json();
  178. adImg2.value = resultAd2.data[0];
  179. })
  180. //4.页面数据 end ---------------------------------------->
  181. //5.设置seo信息 start---------------------------------------->
  182. const setData = await requestDataPromise('/web/getWebsiteFootInfo', {
  183. method: 'GET',
  184. query: {},
  185. });
  186. let seoTitle = setData.data.website_head.title;
  187. let seoDescription = setData.data.website_head.description;
  188. let seoKeywords = setData.data.website_head.keywords;
  189. let seoSuffix = setData.data.website_head.suffix;
  190. let seoName = setData.data.website_head.website_name;
  191. useSeoMeta({
  192. title: seoTitle + "_" + seoSuffix,
  193. meta: [
  194. { name: 'description', content: seoDescription + "_" + seoName + "_" + seoSuffix , tagPriority: 10 },
  195. { name: 'keywords', content: seoKeywords + "_" + seoName + "_" + seoSuffix , tagPriority: 10 },
  196. { name: 'viewport', content: 'width=device-width,initial-scale=1,user-scalable=no',tagPriority: 10 }
  197. ]
  198. });
  199. //5.设置seo信息 end---------------------------------------->
  200. </script>
  201. <style lang="less" scoped>
  202. @import url('@/assets/css/search.less');
  203. </style>
  204. <style lang="less" scoped>
  205. @media screen and (min-width:801px){/*pc*/
  206. .pagination_pc_none{display:none!important;}
  207. .pc_none{display:none;}
  208. }
  209. @media screen and (max-width:800px){/*ipad_phone*/
  210. .breadcrumb{margin-bottom:10px; }
  211. .breadcrumb .location{ font-size: 14px; }
  212. .breadcrumb span { font-size: 14px; }
  213. .newsList{width:100%;margin-bottom:22px;}
  214. .newsList .inner{width:92%!important;}
  215. .newsList .inner .innerLeft > .list > li{width:96%;margin:0px auto;}
  216. .newsList .inner .innerLeft{width:100%;border-top:solid 1px #004564;}
  217. .newsList .inner .innerLeft > .list > li{line-height:50px;}
  218. .newsList .inner .innerLeft > .list > li > a{
  219. width:100%;display:block; height:50px;line-height:50px;font-size:16px;
  220. word-break: keep-all; white-space: nowrap;overflow:hidden;text-overflow:ellipsis;
  221. }
  222. .newsList .inner .innerLeft > .list > li a{float:left;width:92%; }
  223. .newsList .inner .innerLeft > .list > li:nth-of-type(-n+2)::after{display: block;height:18px;margin:10px 0px 0px 0px;
  224. font-size:12px;line-height:18px;float:right;}
  225. .newsList .inner .innerLeft > .pagination{width:100%;}
  226. .newsList .inner .innerLeft > .list{margin:10px auto 10px;}
  227. .newsList .inner .innerLeft > .pagination{margin-bottom:11px;}
  228. .newsList .inner .innerRight {width:100%;display:none;}
  229. .index_foot{margin-top:11px;}
  230. .search{ overflow:hidden;height:auto;
  231. width:92%;margin:10px auto;
  232. .inner{width:100%;display:flex;height:auto;padding:0;}
  233. .inner > input{ flex:1;width:auto;line-height:33px;height:33px;box-sizing:border-box;font-size:14px;}
  234. .inner > button{width:auto;padding:0px 8px;line-height:33px;height:33px;font-size:14px;}
  235. }
  236. ::v-deep .el-pager li{
  237. margin:0px 4px!important;
  238. }
  239. .advert_box{width:92%;margin:0px auto;}
  240. .pagination_phone_none{display:none!important;}
  241. .newsList .inner .innerLeft > .list > li{line-height:40px;height:40px;padding:0!important;}
  242. .newsList .inner .innerLeft > .list > li a{line-height:40px;height:40px;}
  243. .newsList .inner .innerLeft > .list > li:nth-child(5n){
  244. height:auto;
  245. padding-bottom:11px!important;
  246. margin-bottom:11px;
  247. }
  248. .breadcrumb_box{
  249. height:22px;width:100%;margin:10px auto;
  250. word-break: keep-all; white-space: nowrap;overflow:hidden;text-overflow:ellipsis;
  251. width:92%;
  252. font-size:14px;
  253. color:#666;
  254. *{
  255. font-size:14px;
  256. display:inline ;
  257. color:#666;
  258. line-height:22px;height:22px;
  259. margin-right:5px;
  260. }
  261. }
  262. .newsList .inner .innerLeft .list li .listText{width:100%;}
  263. .newsDetail .inner .innerLeft .LeftTop > p{height:auto;}
  264. .phone_none{display:none;}
  265. }
  266. </style>